package com.example.tellwin.home.presenter;

import com.apkfuns.logutils.LogUtils;
import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ActivitiesBean;
import com.example.tellwin.home.bean.ActivityContentBean;
import com.example.tellwin.home.bean.ColumnBean;
import com.example.tellwin.home.bean.ContentBean;
import com.example.tellwin.home.bean.ListContentBean;
import com.example.tellwin.home.bean.QuestionBean;
import com.example.tellwin.home.bean.QuestionContentBean;
import com.example.tellwin.home.bean.TeactherTeamBean;
import com.example.tellwin.home.contract.AnswerHomeContract;
import com.example.tellwin.home.contract.NormalHomeContract;
import com.example.tellwin.mine.bean.ExpenseRecordContentBean;
import com.example.tellwin.utils.HttpUtils;
import com.example.tellwin.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/11/25
 * @Describe ：
 **/
public class AnwerHomePresenter extends RxPresenter<AnswerHomeContract.View> implements AnswerHomeContract.Presenter<AnswerHomeContract.View> {

    private TwjfApi mApi;

    private int pages;
    private int pageNum;
    private final int pageSize = 10;
    private boolean isNotMore = true;

    @Inject
    public AnwerHomePresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }

    @Override
    public void getTopStatistics() {
        mApi.getTopStatistics(new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                if (contentBean.getAnswerStatistics() != null) {
                    mView.topStatisticsResult(contentBean.getAnswerStatistics());
                } else {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                }
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void getAnswerQuestionList() {
        pageNum = 1;
        pages = 0;
        isNotMore = false;
        mApi.getAnswerQuestionList(pageNum + "", pageSize + "",new SimpleCallback<ListContentBean>(mView) {
            @Override
            public void onSuccess(ListContentBean contentBean) {
                pageNum = contentBean.getPageNum();
                pages = contentBean.getPages();
                if (contentBean.getAnswerList() == null || contentBean.getAnswerList().size() == 0) {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMore = true;
                    return;
                }
                if(contentBean.getAnswerList().size()<pageSize){
                    isNotMore = true;
                }
                mView.answerQuestionListResult(contentBean.getAnswerList());

            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void loadMore() {
        if (isNotMore) {
            return;
        }
        if (pages != 0 && pageNum == pages) {
            ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
            isNotMore = true;
            return;
        }
        pageNum++;
        mApi.getAnswerQuestionList(pageNum + "", pageSize + "", new SimpleCallback<ListContentBean>(mView) {
            @Override
            public void onSuccess(ListContentBean contentBean) {
                pageNum = contentBean.getPageNum();
                pages = contentBean.getPages();
                if (contentBean.getAnswerList() == null || contentBean.getAnswerList().size() == 0) {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMore = true;
                    return;
                }
                if(contentBean.getAnswerList().size()<pageSize){
                    isNotMore = true;
                }
                mView.loadMoreResult(contentBean.getAnswerList());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
